#include "languagecontrol.h"

LanguageControl::LanguageControl(QQmlEngine* engine)
    : m_Engine(engine)
{
    m_Translator = new QTranslator(this);

    QCoreApplication::installTranslator(m_Translator);
}

void LanguageControl::load(int index)
{
    if(index == 1)
    {
        qDebug()<<"加载 中文";
        if(m_Translator->load(QCoreApplication::applicationDirPath()+"/Translation/zh_CN.qm"))
        {
            qDebug()<<"加载中文成功";
        }
    }
    else if(index == 2)
    {
        qDebug()<<"加载 英文";
        // if(m_Translator->load("F:/cnc-double-head-saw/CNC_Double_Head_Saw/Translation/en_US.qm"))
        if(m_Translator->load(QCoreApplication::applicationDirPath()+"/Translation/en_US.qm"))
        {
            qDebug()<<"加载成功 - English";
        }
    }
    else if(index == 3)
    {
        qDebug()<<"加载 越南文";
        if(m_Translator->load(QCoreApplication::applicationDirPath()+"/Translation/vi_VN.qm"))
        {
            qDebug()<<"加载成功 - Vin_VN";
        }
    }
    else
    {
        qDebug()<<"加载 中文";
        if(m_Translator->load(QCoreApplication::applicationDirPath()+"/Translation/zh_CN.qm"))
        {
            qDebug()<<"加载中文成功";
        }
    }

    m_Engine->retranslate();

}

int LanguageControl::CurrentType() const
{
    return m_CurrentType;
}

void LanguageControl::setCurrentType(int newCurrentType)
{
    if (m_CurrentType == newCurrentType)
        return;
    m_CurrentType = newCurrentType;
    emit CurrentTypeChanged();
}
